package com.ctl.shardingsphere;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;

import java.util.Arrays;

@SpringBootApplication
@EnableCaching
@Slf4j
public class ShardingsphereApplication extends SpringBootServletInitializer implements CommandLineRunner {

    public static void main(String[] args) {
        ConfigurableApplicationContext run = SpringApplication.run(ShardingsphereApplication.class, args);
    }

    @Override

    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(ShardingsphereApplication.class);
    }

    @Autowired
    private ApplicationContext appContext;

    @Override
    public void run(String... args) throws Exception {
        String[] beans = appContext.getBeanDefinitionNames();
        Arrays.sort(beans);
        for (String bean : beans) {
            if (!bean.startsWith("org")){
                System.out.println(bean + " of Type :: " + appContext.getBean(bean).getClass());
            }
        }
    }
}
